package com.glodon.paas.document.dao.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.glodon.paas.document.api.bean.Project;
import com.glodon.paas.document.service.util.DocumentBuilder;
import com.glodon.paas.util.BeanFactoryUtil;
import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;

@Entity(value = "file", noClassnameStored = true)
public class ProjectInfoEntity {

    public static DocumentBuilder builder = null;

    public static Project getDto(ProjectInfoEntity e) {
        return getDto(e, false);
    }

    public static Project getDto(ProjectInfoEntity e, boolean cascade) {
        if (e == null) {
            return null;
        } else {
            Project d = new Project();
            d.setId(e.getId());
            d.setCreateTime(e.getCreateTime());
            d.setDelete(e.getIsDelete());
            d.setExtension(e.getExtension());
            d.setName(e.getName());
            d.setOwnerId(e.getOwnerId());
            d.setUpdateTime(e.getUpdateTime());
            d.setFolderId(e.getFolderId());
            d.setDescription(e.getDescription());
            if (cascade) {
                if (builder == null) {
                    builder = BeanFactoryUtil.getBean(DocumentBuilder.class);
                }
                d.setOwner(builder.buildUser(e.getOwnerId()));
            }
            return d;
        }
    }

    public static List<Project> getDtos(List<ProjectInfoEntity> es) {
        if (es == null) {
            return null;
        } else {
            List<Project> ds = new ArrayList<Project>(es.size());
            for (ProjectInfoEntity e : es) {
                ds.add(getDto(e));
            }
            return ds;
        }
    }

    @Id
    private String id;
    private String name;
    private String ownerId;
    private Date   createTime;
    private Date   updateTime;
    private String extension;
    private int    isDeleted;
    private String folderId;
    private String description;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getOwnerId() {
        return ownerId;
    }

    public void setOwnerId(String ownerId) {
        this.ownerId = ownerId;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getExtension() {
        return extension;
    }

    public void setExtension(String extension) {
        this.extension = extension;
    }

    public boolean getIsDelete() {
        return isDeleted == 1;
    }

    public void setIsDelete(int isDelete) {
        this.isDeleted = isDelete;
    }

    public String getFolderId() {
        return folderId;
    }

    public void setFolderId(String folderId) {
        this.folderId = folderId;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

}
